function Y = caffe(X, net_file, net_model, phase)

%%
net_file = srdata.checkFileFormat(net_file, '.prototxt');
net_model = srdata.checkFileFormat(net_model, '.caffemodel');

%%
mycaffe.reset_all();

net = caffe.Net(net_file, net_model, phase);

[w, h, c, n] = size(X);
if c > 1
    n = c * n; c = 1;
    X = reshape(X, [w, h, 1, n]);
end

net.blobs('data').reshape([w, h, c, n]);
net.reshape();

net.forward({X});
Y = single(net.blobs(net.outputs{1}).get_data()) ;

mycaffe.reset_all();
